#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
struct ip{
	int a,b,c,d,e;
	string type;
}ip[1001];
int main(){
//	freopen("network.in","r",stdin);
//	freopen("network.out","w",stdout);
	int a;
	cin>>a;
	string op[a+10],s[a+10];
	for(int i=0;i<a;i++){
		cin>>op[i]>>s[i];
	}
	for(int i=0;i<a;i++){
		int b=0,flag=0,j,flag1=0;
		for(j=s[i].size()-1;j>=0;j--){
			if(s[i][j]>='0'&&s[i][j]<='9'){
				ip[i].e+=int(s[i][j])*pow(10,b);
				b++;
			}
			else if(s[i][j]==':'){
				break;
			}
			else{
				flag=1;
			}
		}
		if(ip[i].e>65535||flag==1){
			cout<<"ERR"<<endl;
			continue;
		}
		b=0;
		for(;j>=0;j--){
			if(s[i][j]>='0'&&s[i][j]<='9'){
				ip[i].d+=int(s[i][j])*pow(10,b);
				b++;
			}
			else if(s[i][j]=='.'){
				break;
			}
			else{
				flag=1;
			}
		}
		if(ip[i].d>255||flag==1){
			cout<<"ERR"<<endl;
			continue;
		}
		b=0;
		for(;j>=0;j--){
			if(s[i][j]>='0'&&s[i][j]<='9'){
				ip[i].c+=int(s[i][j])*pow(10,b);
				b++;
			}
			else if(s[i][j]=='.'){
				break;
			}
			else{
				flag=1;
			}
		}
		if(ip[i].c>255||flag==1){
			cout<<"ERR"<<endl;
			continue;
		}
		b=0;
		for(;j>=0;j--){
			if(s[i][j]>='0'&&s[i][j]<='9'){
				ip[i].b+=int(s[i][j])*pow(10,b);
				b++;
			}
			else if(s[i][j]=='.'){
				break;
			}
			else{
				flag=1;
			}
		}
		if(ip[i].b>255||flag==1){
			cout<<"ERR"<<endl;
			continue;
		}
		b=0;
		for(;j>=0;j--){
			if(s[i][j]>='0'&&s[i][j]<='9'){
				ip[i].a+=int(s[i][j])*pow(10,b);
				b++;
			}
			else if(s[i][j]=='.'){
				break;
			}
			else{
				flag=1;
			}
		}
		if(ip[i].a>255||flag==1){
			cout<<"ERR"<<endl;
			continue;
		}
		b=0;
		ip[i].type=op[i];
		for(j=0;j<i;j++){
			if(ip[i].a==ip[j].a&&ip[i].b==ip[j].b&&ip[i].c==ip[j].c&&ip[i].d==ip[j].d&&ip[i].e==ip[j].e&&ip[i].type==ip[j].type){
				flag1=1;
				break;
			}
		}
		if(flag1==1){
			cout<<"FAIL"<<endl;
			continue;
		}
		if(ip[i].type=="Server"){
			cout<<"OK"<<endl;
			continue;
		}
		else if(ip[i].type=="Client"&&flag==0){
			ip[i].type=="Server";
			for(j=0;j<i;j++){
				if(ip[i].a==ip[j].a&&ip[i].b==ip[j].b&&ip[i].c==ip[j].c&&ip[i].d==ip[j].d&&ip[i].e==ip[j].e&&ip[i].type==ip[j].type&&ip[j].type=="Server"){
					ip[i].type=="Client";
					flag1=1;
					cout<<j<<endl;
					break;
				}
			}
		}
	}
	return 0;
}
